﻿Public Class RELIGION

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_MASRELIGION As New PROVIDERSCLASS

    Private Sub RELIGION_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridreligion()

        DesignForm(Me)
        DesignGrid(MASRELIGIONGrid)

        PROVIDER_MASRELIGION.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridreligion()
        Dim objSelectDatamasreligion As New masreligion
        Dim MASRELIGION As DataTable
        MASRELIGION = connect.GetTable(objSelectDatamasreligion.selectMasreligion_)
        MASRELIGIONGrid.PrimaryGrid.DataSource = MASRELIGION
    End Sub

    Private Sub MASRELIGIONGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASRELIGIONGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสศาสนา").Value() IsNot DBNull.Value Then
            RELIGIONIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสศาสนา").Value()
        Else
            RELIGIONIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ศาสนา").Value() IsNot DBNull.Value Then
            RELIGIONTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ศาสนา").Value()
        Else
            RELIGIONTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            religionStatusCheckbox.Checked = True
        Else
            religionStatusCheckbox.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masreligion SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `religion` = '" & RELIGIONIDTxt.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        'connectlocal = conlocal.NewConnection()
        'If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
        '    Try
        '        Dim Sql As String
        '        connectlocal.BeginTrans()
        '        Sql = "UPDATE MASRELIGION SET "
        '        If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
        '            Sql += "[STATUS] = 1 "
        '        Else
        '            Sql += "[STATUS] = 0 "
        '        End If
        '        Sql += "WHERE [RELIGION] = '" & RELIGIONIDTxt.Text & "' ;"

        '        connectlocal.ExecuteNonQuery(Sql)
        '        connectlocal.CommitTrans()
        '    Catch ex As Exception
        '        connectlocal.RollbackTrans()
        '        MsgBox(ex.ToString)
        '    End Try
        'End If
        'connectlocal.Dispose()
        addReligion.Enabled = False
    End Sub

    Private Sub addReligion_Click_1(sender As Object, e As EventArgs) Handles addReligion.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASRELIGION.PADD_ = True Then
                Dim objInsertData As New masreligion
                objInsertData.religionDESC_ = RELIGIONTxt.Text
                objInsertData.religionStatus_ = religionStatusCheckbox.Checked
                objInsertData.insertMasreligionData()

                SelectDatagridreligion()

                RELIGIONIDTxt.Text = ""
                RELIGIONTxt.Text = ""
                religionStatusCheckbox.Checked = False
            Else
                MsgBox(PROVIDER_MASRELIGION.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editReligion_Click_1(sender As Object, e As EventArgs) Handles editReligion.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASRELIGION.PUPD_ = True Then
                Dim editStat As Integer
                editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลอาชีพดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                If editStat = 1 Then
                    Dim objEditData As New masreligion
                    objEditData.religionID_ = CInt(RELIGIONIDTxt.Text)
                    objEditData.religionDESC_ = RELIGIONTxt.Text
                    objEditData.religionStatus_ = religionStatusCheckbox.Checked
                    objEditData.editMasreligionData()

                    SelectDatagridreligion()

                    RELIGIONIDTxt.Text = ""
                    RELIGIONTxt.Text = ""
                    religionStatusCheckbox.Checked = False
                End If
            Else
                MsgBox(PROVIDER_MASRELIGION.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL(masreligion.Text)
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL(masreligion.Text)
        nextform.ShowDialog()
    End Sub
End Class